var $ = require('../../utils/Ajax.js');
Page({
  data: {
    w: "280",
    h: '420',
    PictureUrl: getApp().PictureUrl,
    imgPath: ''
  },
  onLoad: function (options) {
    var that = this;
    wx.setNavigationBarTitle({
      title: "生成图片"
    })
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          w: res.windowWidth * 0.9,
          h: res.windowHeight * 0.8
        });
      }
    })


    var Type = options.Type;
    var Id = options.Id;
    $.Ajax("api/x_cav", "POST", {
      id: Id,
      t: Type
    }, function (res) {
      if(res.s){
        that.setData({
          imgPath: res.d.img
        })
      }else{
        wx.showToast({
          title: res.m,
          icon: 'none',
          duration: 2000
        })
      }
    });
  },
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  },
  savetup: function () {
    var that = this;
    wx.getImageInfo({
      src: that.data.PictureUrl + that.data.imgPath,
      success: function (res) {
        console.log(that.data.PictureUrl + that.data.imgPath)
        wx.saveImageToPhotosAlbum({
          filePath: res.path,
          success(data) {
            wx.showModal({
              title: '存图成功',
              content: '图片成功保存到相册了，去发圈噻~',
              showCancel: false,
              confirmText: '好哒',
              confirmColor: '#72B9C3',
              success: function (res) {
                if (res.confirm) {
                  console.log('用户点击确定');
                }
              }
            })
          }
        })
      }
    })
  }
})